在[Day 9]-【STM32系列】GPIO應用篇- 7 segment led display這篇文章中我們介紹到7段顯示器的應用,但是在實際上撰寫多工掃描程式時CPU只能專注在掃描電路上,無法有多的時間去做其他事情,就等於我們無法同時偵測按鈕輸入、另一邊掃描電路,在偵測按鈕的同時,顯示器會停頓一下,可這不是我們要的結果,所以我們就剛好需要"中斷"這個東西來彌補我們的不足。
#include "main.h"
#include "stm32l0xx_hal.h"
unsigned char segs[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
unsigned char cnt[]={1,2,3,4};
int i,scnt=0;
void display(void){
for(i=0;i<=3;i++){
GPIOA->BRR=0xFF;
GPIOB->BSRR=0x0F;
GPIOA->BSRR = segs[cnt[i]];
GPIOB->BRR = (1<<i);
HAL_Delay(1);
}
}
extern TIM_HandleTypeDef htim6;
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim){
display();
}
void mycodes(void){
GPIOA->BRR=0xFF;
GPIOB->BSRR=0x0F;
HAL_TIM_Base_Start_IT(&htim6);
while(1){
//display();
}
}
- STM32 Nucleo-64 boards (MB1136)資料手冊
https://www.st.com/resource/en/user_manual/dm00105823-stm32-nucleo-64-boards-mb1136-stmicroelectronics.pdf- STM32L053R8 datasheet
https://www.st.com/resource/en/datasheet/stm32l053r8.pdf- RM0367 Reference manual Ultra-low-power STM32L0x3 advanced Arm®-based 32-bit MCUs
https://www.st.com/resource/en/reference_manual/dm00095744-ultra-low-power-stm32l0x3-advanced-arm-based-32-bit-mcus-stmicroelectronics.pdf- ARM Mbed官網介紹 - NUCLEO-L053R8
https://os.mbed.com/platforms/ST-Nucleo-L053R8/- STM32 官網介紹 - STM32L053R8
https://www.st.com/en/microcontrollers-microprocessors/stm32l053r8.html#overview
- 此開發板售價在臺幣1000元以下,讀者可於以下網站購得:
https://www.mouser.tw/
https://www.digikey.tw/
中斷真的是非常強大的東西!!!